package com.yungu.swift.admin.route.operation;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yungu.swift.admin.base.CurrentUser;
import com.yungu.swift.assets.driver.model.dto.DriverMessageDto;
import com.yungu.swift.assets.driver.model.param.AdminDriverMessagePageParam;
import com.yungu.swift.assets.driver.model.param.AdminDriverMessageParam;
import com.yungu.swift.assets.driver.service.DriverMessageService;
import com.yungu.swift.assets.driver.service.DriverService;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.model.PageVo;
import com.yungu.swift.base.model.admin.AdminParam;
import com.yungu.swift.base.model.admin.AdminUuidParam;
import com.yungu.swift.base.model.annotation.ResponseImgOverride;
import com.yungu.swift.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

/**
 * @author : cuixiuyin
 * @date : 2019/6/26
 */
@RestController
@RequestMapping("/admin/v1/operation/driver/message")
@Api(value = "【运营管理】", tags = "司机消息管理")
public class DriverMessageAdmin {

    @Reference
    private DriverMessageService driverMessageService;
    @Reference
    private DriverService driverService;

    @ResponseImgOverride
    @RequestMapping(value = "/queryPage", method = RequestMethod.POST)
    @ApiOperation(value = "司机消息管理分页查询", httpMethod = "POST")
    public ResponseData<PageVo<DriverMessageDto>> queryPage(@RequestBody AdminDriverMessagePageParam driverMessagePageParam) {
        return driverMessageService.queryPage(driverMessagePageParam);
    }

    @ResponseImgOverride
    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    @ApiOperation(value = "司机消息详情", httpMethod = "GET")
    public ResponseData<DriverMessageDto> detail(@RequestParam(value = "uuid") String uuid, @CurrentUser AdminParam adminParam) {
        return driverMessageService.get(uuid);
    }

    @RequestMapping(value = "/recall", method = RequestMethod.POST)
    @ApiOperation(value = "司机消息撤回", httpMethod = "POST")
    public ResponseData<Boolean> recall(@RequestBody AdminUuidParam adminUuidParam) {
        return driverMessageService.recall(adminUuidParam.getUuid());
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ApiOperation(value = "司机消息新增", httpMethod = "POST")
    public ResponseData<Boolean> save(@RequestBody AdminDriverMessageParam driverMessageParam) {
        if (StringUtils.isNotEmpty(driverMessageParam.getUserAgentUuid())) {
            driverMessageParam.setAgentUuid(driverMessageParam.getUserAgentUuid());
        }
        if (StringUtils.isNotEmpty(driverMessageParam.getUserCompanyUuid())) {
            driverMessageParam.setCompanyUuid(driverMessageParam.getUserCompanyUuid());
        }
        return driverMessageService.saveAndSend(driverMessageParam);
    }
}
